package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.Setmeal;
import com.xrit.sunnyday.service.SetmealService;
import com.xrit.sunnyday.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealMobileController {
    @Reference
    private SetmealService setmealService;

    /**
     * 查询所有的套餐
     */
    @GetMapping("/getSetmeal")
    public Result getSetmeal(){
        List<Setmeal> setmealList = setmealService.findAll();
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
    }

    @GetMapping("/findDetailById")
    public Result findDetailById(int id){
        Setmeal  setmeal= setmealService.findDetailById(id);
        //setmeal.setImg(QiNiuUtils.DOMAIN+setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmeal);
    }

    /**
     * 查询套餐的基本信息
     */
    @GetMapping("/findById")
    public Result findById(int id){
        // 根据id查询套餐
        Setmeal setmeal = setmealService.findById(id);
        // 后台设置套餐图片显示路径
        setmeal.setImg(QiNiuUtils.DOMAIN+setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}
